package com.bw.ppjokeplay.commen.network

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**
 * @author Lishaohe
 * @description:
 * @date :2021/11/10 0010 上午 10:49
 *
 */
class ApiServer private constructor(){
    companion object{
        private var apiServer : ApiServer?=null
        get() {
            if (field==null){
                field = ApiServer()
            }
            return field
        }
        fun instance():ApiServer{
            return  apiServer!!
        }
    }

    fun getRetrofit():Retrofit?{
        val okBuilder : OkHttpClient.Builder = OkHttpClient.Builder()
        val loggerInterceptor:HttpLoggingInterceptor = HttpLoggingInterceptor()
        loggerInterceptor.level = HttpLoggingInterceptor.Level.BODY
        okBuilder.addInterceptor(loggerInterceptor)
        okBuilder.readTimeout(30,TimeUnit.SECONDS)
        okBuilder.connectTimeout(30,TimeUnit.SECONDS)
        okBuilder.writeTimeout(30,TimeUnit.SECONDS)
        val build : Retrofit.Builder = Retrofit.Builder()
        build.client(okBuilder.build())
        build.baseUrl(Api.BASEURL)
        build.addConverterFactory(GsonConverterFactory.create())
        build.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        return build.build()
    }

}